package com.iplant.mes.controller.sfc;

import com.iplant.base.po.ServiceResult;
import com.iplant.base.utils.RetCode;
import com.iplant.base.utils.general.StringUtils;
import com.iplant.basic.controller.BasicController;
import com.iplant.basic.service.po.bms.BMSEmployee;
import com.iplant.mes.service.SFCFrockBindService;
import com.iplant.mes.service.po.sfc.SFCWorkpieceExportRecord;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * 工件导出记录
 *
 * @author YouWang·Peng
 * 2023-9-14 10:05:51
 */
@RestController
@RequestMapping("/api/SFCWorkpieceExportRecord")
public class SFCWorkpieceExportRecordController extends BasicController<SFCWorkpieceExportRecord> {
    private static final Logger logger = LoggerFactory.getLogger(SFCWorkpieceExportRecordController.class);

    public SFCWorkpieceExportRecordController() {
        super(SFCWorkpieceExportRecord.class);
    }

    @Autowired
    SFCFrockBindService mSFCFrockBindService;

    /**
     * 导出工件相关记录
     */
    @GetMapping("/Export")
    public Object QueryPendingCompletionConfirmationFilterItem(HttpServletRequest request) {
        Object wResult = new Object();
        try {
            BMSEmployee wLoginUser = GetSession(request);

            Map<String, Object> wParams = GetParamsMap(request);

            ServiceResult<SFCWorkpieceExportRecord> wServiceResult = mSFCFrockBindService.SFC_ExportWorkpieceRecord(wLoginUser, wParams);

            if (StringUtils.isEmpty(wServiceResult.FaultCode)) {
                wResult = GetResult(RetCode.SERVER_CODE_SUC, "", null, wServiceResult.Result);
            } else {
                wResult = GetResult(RetCode.SERVER_CODE_SUC, wServiceResult.FaultCode);
            }
        } catch (Exception ex) {
            logger.error(ex.toString());
            wResult = GetResult(RetCode.SERVER_CODE_ERR, ex.toString(), null, null);
        }
        return wResult;
    }
}
